import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.navigation.DifferentialPilot;


public class Sensor {
	
    static DifferentialPilot Pilot = new DifferentialPilot(3f,12.7f,Motor.A,Motor.C);
	static UltrasonicSensor Sonic = new UltrasonicSensor(SensorPort.S4);
	static int distSen=0;
	public static void main(String[] args) throws Exception {
		
		LCD.drawString("'Sensor'", 0, 1);
		 Button.waitForAnyPress();
		 LCD.drawString("'PRESIONE ENTER'", 0, 3);
		 Button.ENTER.waitForPress();
	while(!Button.ESCAPE.isPressed()){	 
		Pilot.travel(100);
		distSen=Sonic.getDistance();
		LCD.drawInt(distSen,4, 0, 7);
		 if (distSen < 30) 
		  {
		Pilot.stop();
		
		

		  }
	}
	}
}


